<?php
namespace app\web\admin;

use app\common\builder\ZBuilder;
use app\web\model\Config as myModel;


/**
 * 轮播管理（后台）
 * @package
 */
class Config extends Base 
{
    public function edit($id = 1) 
    {
        
        if ($this->request->isPost()) {
            $data = $this->request->post();
            $data['share_posters'] = $this->setImgPath($data['share_posters_id']);
            $data['promise_path'] = $this->setImgPath($data['promise_path_id']);
            $data['shop_promise_path'] = $this->setImgPath($data['shop_promise_path_id']);
            $info = myModel::get(1);
            if($info->save($data)) $this->success('编辑成功', url('edit',['id'=>1]));
            $this->error('编辑失败');
        }
        $info = myModel::get(1)->toArray();
        $info['order_hour'] = $info['order_hour']/3600;
        $info['order_cancel_time'] = $info['order_cancel_time']/60;
        $info['unconfirmed_times'] = $info['unconfirmed_times']/60;
        $info['order_complete_time'] = $info['order_complete_time']/3600;
        $info['offline_day'] = $info['offline_day']/86400;
        $info['service_start_before'] = $info['service_start_before']/60;
        return  ZBuilder::make('form')
            ->setPageTitle('修改')
            ->addFormItems([
                ['hidden','id'],
                ['number:6','integral_rate','积分抵扣比','0.1表示10%'],
                ['number:6','order_integral_rate','订单消费奖励积分比','0.1表示10%'],
                ['number:6','deal_dat','N天内订单成交排序'],
                ['text:6','complaint_money','平台投诉电话'],
                ['text:6','wx_code','商务微信号'],
                ['number:6','service_start_before','服务开始前N分钟通知技师(分钟)'],                
                ['number:6','order_cancel_time','订单N分钟未支付自动取消','单位(分)'],
                ['number:6','unconfirmed_times','订单N分钟未确认自动取消','单位(分)'],
                ['number:6','order_complete_time','订单N小时未完成自动完成','单位(小时)'],
                ['number:6','order_hour','预约时间N小时前退款只扣除平台服务费','单位(时)'],
                ['number:6','platform_service_rate','退款平台服务费率','0.1表示10%'],
                ['number:6','delay_work_money','技师误工费','单位(元)'],
                ['number:6','sub_ordinary_rate','分销下级用户消费佣金百分比','0.1表示10%'],
                ['number:6','sub_technician_rate','分销下级技师订单佣金百分比','0.1表示10%'],
                ['number:6','sub_shop_rate','分销下级商户订单佣金百分比','0.1表示10%'],
                ['number:6','offline_day','技师N天未定位自动下线(天)'],
                ['image','share_posters_id','分享海报','建议尺寸750*1000'],
                ['file','promise_path_id','技师承诺函'],
                ['file','shop_promise_path_id','商户承诺函'],
                ['ueditor','agreement','上门服务协议'],
                ['ueditor','cost_description','费用说明'],
                ['ueditor','recharge_rules','充值规则'],
                ['ueditor','service_agreement','服务协议'],
                ['ueditor','distribution_rules','分销规则'],
                ['ueditor','technician_notice','技师入驻须知'],
                ['ueditor','order_notice','下单须知'],
                ['ueditor','reserve_notice','预订须知'],
                ['ueditor','platform_guarantee','平台担保'],
                ['ueditor','official_certification','官方认证'],
                ['ueditor','transparent_charges','收费透明'],
                ['ueditor','break_refund','爽约包退'],
            ])
            ->setFormData($info)
            ->fetch();
    }
}